package com.topka.buynewcar.android.cases;

import org.junit.Test;

import com.topka.buynewcar.android.pages.AskPricePage;
import com.topka.buynewcar.android.pages.ChooseCarBrandPage;
import com.topka.buynewcar.android.pages.ChooseCarNamePage;
import com.topka.buynewcar.android.pages.ChooseCarTypePage;
import com.topka.buynewcar.android.pages.ChooseCityPage;
import com.topka.buynewcar.android.pages.HomePage;
import com.topka.buynewcar.android.pages.LoginAccountPage;
import com.topka.buynewcar.android.pages.LoginFastPage;
import com.topka.buynewcar.android.pages.MineFragmentPage;
import com.topka.buynewcar.android.pages.NewBuyCarMainFragmentPage;
import com.topka.buynewcar.base.AndroidAppBaseTest;
import com.topka.buynewcar.utils.Utils;

public class AskPriceCase extends AndroidAppBaseTest {

	public HomePage homePage;
	public NewBuyCarMainFragmentPage buycarPage;
	public MineFragmentPage minePage;
	public AskPricePage askPricePage;
	public LoginFastPage loginFastPage;
	public LoginAccountPage loginAccountPage;
	public ChooseCarBrandPage chooseCarBrand;
	public ChooseCarNamePage chooseCarName;
	public ChooseCarTypePage chooseCarType;
	public ChooseCityPage chooseCity;

	@Override
	public void setUp() throws Exception {
		super.setUp();
		homePage = new HomePage(wd);
		buycarPage = new NewBuyCarMainFragmentPage(wd);
		minePage = new MineFragmentPage(wd);
		askPricePage = new AskPricePage(wd);
		loginFastPage = new LoginFastPage(wd);
		loginAccountPage = new LoginAccountPage(wd);
		chooseCarBrand = new ChooseCarBrandPage(wd);
		chooseCarName = new ChooseCarNamePage(wd);
		chooseCarType = new ChooseCarTypePage(wd);
		chooseCity = new ChooseCityPage(wd); 
	}

	@Test
	public void askPrice() throws Exception {
		Utils.sleep(10);
		buycarPage.clickAskPriceLayout();
		Utils.sleep(3);
		askPricePage.clickChooseCar();
		Utils.sleep(3);
		chooseCarBrand.clickSideBarWord("Z");
		Utils.sleep(3);
		chooseCarBrand.clickCarBrand("众泰");
		Utils.sleep(3);
		chooseCarName.clickCarName();
		Utils.sleep(3);
		chooseCarType.clickCarTypeRandom();
		Utils.sleep(3);
		askPricePage.swipeToBottom();
		Utils.sleep(3);
		String city = askPricePage.getCity();
		if(city==null||city.equals("请选择")){
			askPricePage.clickCity();
			Utils.sleep(3);
			chooseCity.clickProvince("西藏");
			Utils.sleep(1);
			chooseCity.clickCity();
			Utils.sleep(3);
		}
		askPricePage.clickAskCity();
		Utils.sleep(3);
		chooseCity.clickProvince("西藏");
		Utils.sleep(1);
		chooseCity.clickCity();
		Utils.sleep(3);
		askPricePage.clickAskPrice();
		Utils.sleep(10);
		try{
			askPricePage.clickAskComplete();
		}catch(Exception e){
			loginFastPage.clickAccountLogin();
			Utils.sleep(3);
			loginAccountPage.setUserName("13581917727");
			loginAccountPage.setPassWord("123456");
			Utils.sleep(3);
			loginAccountPage.clickLogin();
			Utils.sleep(10);
			askPricePage.clickAskPrice();
			Utils.sleep(10);
		}
		askPricePage.clickAskComplete();
		Utils.sleep(10);
	}

}
